import { ref, onMounted, onUnmounted } from "vue"

export default function useMousePosition() {
    const x = ref(-1)
    const y = ref(-1)

    const updatePosition = (e) => {
        x.value = e.pageX
        y.value = e.pageY
    }

    // 挂在后绑定监听
    onMounted(() => {
        document.addEventListener("click", updatePosition)
    })

    // 卸载监听
    onUnmounted(() => {
        document.removeEventListener("clcik", updatePosition)
    })

    return { x, y }
}